﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using Tools;

namespace Punia
{
    [CommandAttribute(false)]
    public partial class anonymous_transport_security : BaseForm
    {
        public anonymous_transport_security()
            : base()
        {
        }

        public anonymous_transport_security(DbContext dbContext)
            : base(dbContext)
        {
            InitializeComponent();

            cbEndpoint.DataSource = Utility.endpoints(dbContext);
            cbEndpoint.DisplayMember = "Name";
        }

        protected override void Write()
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("USE master;");
            if (cbEndpoint.SelectedIndex > 0)
                sb.AppendLine("GRANT CONNECT ON ENDPOINT::[" + cbEndpoint.Text + "] TO [PUBLIC]");
            else
                sb.AppendLine("GRANT CONNECT ON ENDPOINT::[] TO [PUBLIC]");

            tbCommand.Text = sb.ToString();
        }

        private void cbEndpoint_SelectedIndexChanged(object sender, EventArgs e)
        {
            Write();
        }
    }
}